<template>
    <div class="dialog" id="dialog" v-show="dShow" >
       <div class="dialog-container" v-bind:style="{width:dWidth+'px',height:dHeight+'px',top:dTop+'px',left:dLeft+'px'}">
        <div class="dialog-title">
            <i class="dialog-title-icon icon-info-sign"></i>
            {{title}}
            <i class="dialog-close " @click="dialogClose">X</i>
        </div>
        <div class="dialog-context" >
            <router-view/>
        </div>
       </div>
        <div class="dialog-mask"></div>
    </div>
</template>
<script>
export default {
    name: "Dialog",
    data(){
        return {
            dShow:false,
            dTop:200,
            dLeft:100,
            dWidth:0,
            dHeight:0,
            title:"",
            callBack:false
        }
    },
    methods:{
        reLocal(width,height){
            this.dLeft =  (window.innerWidth - width)/2;
            this.dTop = (window.innerHeight - height) /2;
        },
        dialogShow(dialogSetting){
            this.title = dialogSetting.title
            this.dShow = true;
            this.dWidth = dialogSetting.width
            this.dHeight = dialogSetting.height
            this.reLocal(this.dWidth,this.dHeight)
            if(dialogSetting.callBack){
                this.callBack = dialogSetting.callBack
            }        
            if(dialogSetting.params){
                this.$router.push({path:dialogSetting.path,params:dialogSetting.params})
            }else{
                this.$router.push({path:dialogSetting.path})
            }
        },
        dialogClose(params){
            this.dShow = false;
            this.$router.go(-1);
            if(this.callBack){
                this.$emit(this.callBack,params)
            }
        }
    }

};
</script>


<style>
.dialog {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.dialog-container{
      z-index: 99;
      position: absolute;
      background: #ffffff;
      border-radius: 4px;
      border:1px solid #ccc;
}
.dialog-title {
    height: 30px;
    line-height: 30px;
    text-align: left;
    background: #409EFF;
    color: #fff;
    font-weight: bold;
}
.dialog-title-icon {
    padding-left:10px;
}
.dialog-context{
  
}
.dialog-close{
    line-height: 30px;
    float:right;
    padding-right:10px;
    font-weight: bold;
    font-size:14px;
    cursor: pointer;
}
.dialog-mask{
    z-index: 20;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
     background: #ccc;
    opacity:0.5;
    filter:Alpha(opacity=50);
}
</style>
